package github.sf.mod.calculate.entity;

import github.sf.mod.calculate.Op;

public class Binary extends Expression {
    private Op op;
    //左边表达式
    private Expression exp1;
    //右边表达式
    private Expression exp2;

    public Binary(Op op, Expression exp1, Expression exp2) {
        this.op = op;
        this.exp1 = exp1;
        this.exp2 = exp2;
    }

    public Op getOp() {
        return op;
    }

    public void setOp(Op op) {
        this.op = op;
    }

    public Expression getExp1() {
        return exp1;
    }

    public void setExp1(Expression exp1) {
        this.exp1 = exp1;
    }

    public Expression getExp2() {
        return exp2;
    }

    public void setExp2(Expression exp2) {
        this.exp2 = exp2;
    }

    @Override
    public void dump(int index) {
        System.out.println("\n" + addPrefix(index) + "二叉树:");
        System.out.println(addPrefix(index) + "运算符:" + op);
        //左边
        System.out.print(addPrefix(index) + "左边:");
        int newIndex = index + 1;
        exp1.dump(newIndex);
        //右边
        System.out.print(addPrefix(index) + "右边:");
        exp2.dump(newIndex);
    }

    @Override
    public Object accept(AstVisitor visitor, Object additional) {
        return visitor.visitBinary(this, additional);
    }

    @Override
    public String toString() {
        return "Binary{" +
                "op=" + op +
                ", exp1=" + exp1 +
                ", exp2=" + exp2 +
                '}';
    }
}
